CSharpTest.Net
Add Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTree<TKey,TValue> Class : Add Method

key
value

Glossary Item Box

Adds an element with the provided key and value to the IDictionary.

Syntax

Visual Basic (Declaration) 
Public Sub Add( _
   ByVal key As TKey, _
   ByVal value As TValue _
) 
C# 
public void Add( 
   TKey key,
   TValue value
)

Parameters

key
value

Example

BPlusTree/BPlusTree.Test/TestMultiInstance.cs

C#Copy Code
using (var tempFile = new TempFile())
using (var logfile = new TempFile())
using (var tempCopy = new TempFile())
{
    var options = new BPlusTree<int, string>.OptionsV2(new PrimitiveSerializer(), new PrimitiveSerializer())
    {
        CreateFile = CreatePolicy.Always,
        FileName = tempFile.TempPath,
        TransactionLogFileName = logfile.TempPath,
    }.CalcBTreeOrder(4, 10);

    var readcopy = options.Clone();
    readcopy.FileName = tempCopy.TempPath;
    readcopy.StoragePerformance = StoragePerformance.Fastest;

    using (var tree = new BPlusTree<int, string>(options))
    using (var copy = new BPlusTree<int, string>(readcopy))
    using (var tlog = new TransactionLog<int, string>(
        new TransactionLogOptions<int, string>(logfile.TempPath, PrimitiveSerializer.Int32, PrimitiveSerializer.String) { ReadOnly = true }))
    {
        tree.Add(0, "0");
        tree.Commit();

        long logpos = 0;
        copy.EnableCount();
        //start by copying the data from tree's file into the copy instance:
        copy.BulkInsert(
            BPlusTree<int, string>.EnumerateFile(options),
            new BulkInsertOptions { InputIsSorted = true, CommitOnCompletion = false, ReplaceContents = true }
            );

        Assert.AreEqual(1, copy.Count);
        Assert.AreEqual("0", copy[0]);

        tlog.ReplayLog(copy, ref logpos);
        Assert.AreEqual(1, copy.Count);

        //insert some data...
        tree.AddRange(MakeValues(1, 99));

        tlog.ReplayLog(copy, ref logpos);
        Assert.AreEqual(100, copy.Count);

        //insert some data...
        for (int i = 0; i < 100; i++)
            tree.Remove(i);
        tlog.ReplayLog(copy, ref logpos);
        Assert.AreEqual(0, copy.Count);

        tree.AddRange(MakeValues(1000, 1000));

        tlog.ReplayLog(copy, ref logpos);
        Assert.AreEqual(1000, copy.Count);
    }
}
VB.NETCopy Code
Using tempFile As var = New TempFile()
    Using logfile As var = New TempFile()
        Using tempCopy As var = New TempFile()
            Dim options As var = New BPlusTree(Of Integer, String).OptionsV2(New PrimitiveSerializer(), New PrimitiveSerializer()) With { _
                Key .CreateFile = CreatePolicy.Always, _
                Key .FileName = tempFile.TempPath, _
                Key .TransactionLogFileName = logfile.TempPath _
            }.CalcBTreeOrder(4, 10)

            Dim readcopy As var = options.Clone()
            readcopy.FileName = tempCopy.TempPath
            readcopy.StoragePerformance = StoragePerformance.Fastest

            Using tree As var = New BPlusTree(Of Integer, String)(options)
                Using copy As var = New BPlusTree(Of Integer, String)(readcopy)
                    Using tlog As var = New TransactionLog(Of Integer, String)(New TransactionLogOptions(Of Integer, String)(logfile.TempPath, PrimitiveSerializer.Int32, PrimitiveSerializer.[String]) With { _
                        Key .[ReadOnly] = True _
                    })
                        tree.Add(0, "0")
                        tree.Commit()

                        Dim logpos As Long = 0
                        copy.EnableCount()
                        'start by copying the data from tree's file into the copy instance:
                        copy.BulkInsert(BPlusTree(Of Integer, String).EnumerateFile(options), New BulkInsertOptions() With { _
                            Key .InputIsSorted = True, _
                            Key .CommitOnCompletion = False, _
                            Key .ReplaceContents = True _
                        })

                        Assert.AreEqual(1, copy.Count)
                        Assert.AreEqual("0", copy(0))

                        tlog.ReplayLog(copy, logpos)
                        Assert.AreEqual(1, copy.Count)

                        'insert some data...
                        tree.AddRange(MakeValues(1, 99))

                        tlog.ReplayLog(copy, logpos)
                        Assert.AreEqual(100, copy.Count)

                        'insert some data...
                        Dim i As Integer = 0
                        While i < 100
                            tree.Remove(i)
                            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
                        End While
                        tlog.ReplayLog(copy, logpos)
                        Assert.AreEqual(0, copy.Count)

                        tree.AddRange(MakeValues(1000, 1000))

                        tlog.ReplayLog(copy, logpos)
                        Assert.AreEqual(1000, copy.Count)
                    End Using
                End Using
            End Using
        End Using
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys